package com.sunlee.common.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sunlee.common.core.constant.Constant;
import com.sunlee.common.core.entity.BaseEntity;
import com.sunlee.common.core.utils.ConvertUtils;
import com.sunlee.common.service.dao.AboutConfigDao;
import com.sunlee.common.service.dto.AboutConfigDTO;
import com.sunlee.common.service.dto.AboutConfigListDTO;
import com.sunlee.common.service.entity.AboutConfigEntity;
import com.sunlee.common.service.service.AboutConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 关于页面配置表
 *
 * @author sunlee
 */
@Service
public class AboutConfigServiceImpl extends CrudServiceImpl<AboutConfigDao, AboutConfigEntity, AboutConfigDTO> implements AboutConfigService {

    @Override
    public LambdaQueryWrapper<AboutConfigEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");
        return new LambdaQueryWrapper<AboutConfigEntity>()
                .eq(StringUtils.isNotBlank(id), AboutConfigEntity::getId, id)
                .orderByAsc(AboutConfigEntity::getSort);
    }

    @Override
    public List<AboutConfigListDTO> getListByType(String type) {
        List<AboutConfigEntity> list = baseDao.selectList(new LambdaQueryWrapper<AboutConfigEntity>()
                .eq(AboutConfigEntity::getStatus, Constant.STATUS_VALID)
                .like(AboutConfigEntity::getType, type)
                .orderByAsc(AboutConfigEntity::getSort));

        return ConvertUtils.sourceToTarget(list, AboutConfigListDTO.class);
    }
}